//
//  U9LaunchManager.m
//  PCode
//
//  Created by uuu9 on 2017/6/2.
//  Copyright © 2017年 UUU9. All rights reserved.
//

#import "U9LaunchManager.h"
//#import "U9VersionModel.h"
#import "U9LaunchAdvertisementModel.h"
#import "U9CatagoryModel.h"

@implementation U9LaunchManager

+(void)getLaunchAdvertisementWithCompletionHandle:(void (^)(U9LaunchAdvertisementModel *, NSError *))complete{
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetLaunchAdvert]
   parameters:nil
completionHandler:^(id responseObj, NSError *error) {
    U9LaunchAdvertisementModel *model = [U9LaunchAdvertisementModel mj_objectWithKeyValues:responseObj];
    if (model.error_code != 0) {
        error = [self createError:model.error_msg];
    }
    complete(model,error); 
}];
}


+(void)getCatagoryWithCompletionHandle:(void (^)(U9CatagoryModel *, NSError *))complete{
    PlistStorage *plist = [PlistStorage sharedPlistStorage];
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetClassCatagory]
   parameters:nil
completionHandler:^(id responseObj, NSError *error) {
    U9CatagoryModel *model = [U9CatagoryModel mj_objectWithKeyValues:responseObj];
    if (model.error_code != 0) {
        error = [self createError:model.error_msg];
        model = [U9CatagoryModel mj_objectWithKeyValues:[plist readFromPlist:@"CatagoryList"]];
    } else if (error) {
        model = [U9CatagoryModel mj_objectWithKeyValues:[plist readFromPlist:@"CatagoryList"]];
    } else {
        [plist storageToPlist:responseObj andFileName:@"CatagoryList"];
    }
    complete(model,error);
}];
    
}



+(void)checkVersionWithCompletionHandle:(void (^)(U9VersionModel *model, NSError *))complete{
    [self EncryptPOST:[NSString stringWithFormat:@"%@%@",Api_URL,kCheckVersion]
           parameters:nil
    completionHandler:^(id responseObj, NSError *error) {
        U9VersionModel *model = [U9VersionModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
    
}


@end
